﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example11.aspx.cs" Inherits="Chapter30.Example11" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 30-11 使用 MouseEvent 对象响应鼠标事件</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style title="cor styles">
        p {
            background: gray;
            color: white;
            padding: 10px;
            margin: 5px;
            border: thin solid black;
        }

        table {
            margin: 5px;
            border-collapse: collapse;
        }

        th, td {
            padding: 4px;
        }
    </style>
</head>
<body>
    <p id="block1">
        There are lots of different kinds of fruit - there are you over 500 varieties 
        of <span id="banana">banana</span> alone. By the time we add the countless 
        types of apples, oranges, and other well-known fruit, we are 
        faced with thousands of choices.
    </p>
    <table border="1">
        <tr>
            <th>Type:</th>
            <td id="type"></td>
        </tr>
        <tr>
            <th>X:</th>
            <td id="x"></td>
        </tr>
        <tr>
            <th>Y:</th>
            <td id="y"></td>
        </tr>
    </table>
    <script>
        var textblock = document.getElementById("block1");
        var typeCell = document.getElementById("type");
        var xCell = document.getElementById("x");
        var yCell = document.getElementById("y");

        textblock.addEventListener("mouseover", handleMouseEvent, false);
        textblock.addEventListener("mouseout", handleMouseEvent, false);
        textblock.addEventListener("mousemove", handleMouseEvent, false);

        function handleMouseEvent(e) {
            if (e.eventPhase == Event.AT_TARGET) {
                typeCell.innerHTML = e.type;
                xCell.innerHTML = e.clientX;
                yCell.innerHTML = e.clientY;

                if (e.type == "mouseover") {
                    e.target.style.background = "black";
                    e.target.style.color = "white";
                } else {
                    e.target.style.removeProperty("color");
                    e.target.style.removeProperty("blackground-color");
                }
            }
        }
    </script>
</body>
</html>
